<?php

/**
 * @desc 响应ERP的相关请求
 * @author zhangweifeng@shopex.cn 15-7-7 上午11:02
 */
class apioubao_erp_response {

	/**
	 * @desc ：返回所有的销售公司数据
	 * @author jeff 2015/07/05 22:54:19
	 * @param 参数类型`
	 * @return 返回值类型
	 */
	function get_companys($params, &$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('abimanage')->model('sales_company')->getList('*', $filter);
	}

	/**
	 * @desc ：返回所有的售点数据
	 * @author jeff 2015/07/05 22:54:19
	 * @param 参数:类型
	 * @return 返回值类型
	 */
	function get_members($params, &$service) {
		/*$where=' mem.check_state="1" ';
		$arr=array();
		$b2c_members_mdl = app::get('b2c')->model('members');
		//2015-9-11 by jiang 最后更新时间小于最后修改时间  提高效率
		if (!empty($params['last_modify'])) {
			$where=' '.$params['last_modify'].' < mem.last_modified'.' and mem.check_state="1"';
		}
		//查出所有要更新和新增的数据
		$sql = 'SELECT
		mem.member_id,mem.name,mem.client_source,mem.sex,mem.advance,mem.regtime,mem.area,mem.tel,mem.mobile,mem.email,mem.remark,mem.com_type,mem.advance,mem.username,mem.co_address,mem.reason,mem.user_type,
		pam.login_account AS uname
		FROM `sdb_b2c_members` AS mem
		LEFT JOIN `sdb_pam_members` AS pam ON mem.member_id=pam.member_id WHERE ' . $where . '
		GROUP BY mem.member_id';
		$arr=$b2c_members_mdl->db->select($sql);*/
		$arr = array();
		$sql = "
			select mem.member_id,mem.name,mem.client_source,mem.sex,mem.advance,mem.regtime,mem.area,mem.tel,mem.mobile,mem.email,mem.remark,mem.com_type,mem.advance,mem.username,mem.co_address,mem.reason,mem.user_type,
			pam.login_account AS uname
			FROM `sdb_b2c_members` AS mem
			LEFT JOIN `sdb_pam_members` AS pam ON mem.member_id=pam.member_id where mem.member_id in
			(select member_id from sdb_b2c_members where check_state='1' and tongbu_state = '0') GROUP BY mem.member_id
		 ";
        $arr = kernel::database()->select($sql);
        $memberIds = utils::_array_column($arr,'member_id');
        if ($memberIds) {
        	app::get('b2c')->model('members')->update(array('tongbu_state'=>1),array('member_id'=>$memberIds));
        }
		return $arr;
	}

	/**
	 * @desc ：获得某个会员的信用额度,包括总信用额度，可用信用额度，实际预存
	 * @author jeff 2015/07/05 22:54:19
	 * @param 参数:类型
	 * @return 返回值类型
	 */
	function get_member_credit($params, &$service) {
		// return array('test'=>'test1111');
		$member_id = $params['member_id'];
		$mem_adv = app::get('b2c')->model('member_advance');
		$arr = $mem_adv->get_xinyong($member_id);
		return $arr;
	}

	/**
	 * @desc 取得销售区域
	 * @return type
	 * @author zhangweifeng@shopex.cn 15-7-8 下午8:38
	 */
	function get_salesarea($params, &$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('abimanage')->model('sales_area')->getList('*', $filter);
	}

	/**
	 * @desc 取得配送日期配置
	 * @return type
	 * @author zhangweifeng@shopex.cn 15-7-10 下午12:25
	 */
	function get_shipdate($params, &$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('abimanage')->model('shipdate')->getList('*', $filter);
	}

	/**
	 * @desc 取得配送时间配置
	 * @return type
	 * @author zhangweifeng@shopex.cn 15-7-10 下午12:25
	 */
	function get_shiptime($params, &$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('abimanage')->model('shiptime')->getList('*', $filter);
	}

	/**
	 * author: talent4636@gmail.com
	 *   date: 2015-7-20 11:01:08
	 *   desc:取得商城中的商品基础数据
	  =========================ERP中需要的字段：===========================
	  名称            字段名/sdf                              说明
	  -------------------------------------------------------------------
	  货品ID			goods[product][0][product_id]    		新建时木有
	  商品类型   		goods[type][type_id]
	  品牌			    goods[brand][brand_id]
	  商品名称		    goods[name]
	  商品编号		    goods[bn]
	  预览图片地址	    goods[picurl]
	  计量单位		    goods[unit]
	  存在唯一码		goods[serial_number]    		   true/false
	  简介			    goods[brief]
	  隐藏			    goods[visibility]       				default=false
	  [hidden]上架	    goods[status]           				only-true
	  销售价			goods[product][0][price][price][price]
	  成本价			goods[product][0][price][cost][price]
	  货号			    goods[product][0][bn]
	  条形码			goods[product][0][barcode]
	  重量			    goods[product][0][weight]
	  {规格暂不考虑}
	 * ---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	 * ---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	 * ---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	  $goodsData = array(
		  'goods_id' => 2,
		  'category' => array(
			  'cat_id' => 0,
		  ) ,
		  'type' => array(
			  'type_id' => 1,
		  ) ,
		  'brand' => array(
			  'brand_id' => '',
		  ) ,
		  'name' => 商品名称2,
		  'bn' => 222222,
		  'picurl' => '',
		  'unit' => g,
		  'serial_number' => false,
		  'brief' => 222222222222,
		  'status' => true,
		  'product' => array(
			  '0' => array(
				  'status' => true,
				  'product_id' => 2,
				  'price' => array(
					  'price' => array(
						  'price' => 222.000,
					  ) ,
					  'cost' => array(
						  'price' => 21.000,
					  ) ,
					  'mktprice' => array(
						  'price' => 0.000,
					  ) ,
				  ) ,
				  'bn' => 222222,
				  'barcode' => '',
				  'weight' => 10.000,
				  'default' => 1,
				  'unit' => g,
				  'visibility' => true,
			  ) ,
		  ) ,
		  'description' => '',
		  'visibility' => true,
		  'keywords' => array(
			  '0' => array(
				  'keyword' => array(
					  'res_type' => 'goods',
				  ) ,
			  ) ,
		  ) ,
		  'spec' => '',
		  'adjunct' => '',
		  'tag' => array() ,
		  'barcode' => '',
	  );

	  =================================END================================
	 */


	  /**
	   * ps ：获取货品信息  用于进销存中同步
	   * Time：2015/09/15 10:44:35
	   * @author jiang
	  */
	function get_product_data($params, &$service) {
		$jxc_modify=$params['last_modify'];
		$modelProduct = app::get('b2c')->model('products');
		//先获取所有的商品  并且必须有货品
		$filter['spec_desc|noequal']=$value[''];
		$sql1= "SELECT
				goods_id,name,bn,
				brief,brand_id,type_id,
				unit,params,p_1,p_2,
				p_3,p_4,p_5,
				p_6,p_7,p_8,
				p_9,p_10,p_11,
				p_12,p_13,p_14,
				p_15,p_16,p_17,
				p_18,p_19,p_20,
				p_21,p_22,p_23,
				p_24,p_25,p_26,
				p_27,p_28,p_29,
				p_30,p_31,p_32,
				p_33,p_34,p_35,
				p_36,p_37,p_38,
				p_39,p_40,p_41,
				p_42,p_43,p_44,
				p_45,p_46,p_47,
				p_48,p_49,p_50
			FROM sdb_b2c_goods
			WHERE erp_modify > '{$jxc_modify}'
			ORDER BY goods_id DESC
			LIMIT 500";
		$goods=kernel::database()->select($sql1);
		//获得产品扩展属性的映射数组
		$sql = "select * from sdb_b2c_goods_type_props where 1";
		$rows = kernel::database()->select($sql);
		$arr_props = array();
		foreach($rows as &$v) {
			$arr_props[$v['type_id']][] = $v;
		}

		//获得扩展属性的type=select的映射数组
		$sql = "select * from sdb_b2c_goods_type_props_value where 1";
		$rows = kernel::database()->select($sql);
		$arr_props_value = array();
		foreach($rows as &$v) {
			$arr_props_value[$v['props_value_id']] = $v;
		}

		//获取商品类型的映射数组
		$sql = "select * from sdb_b2c_goods_type where 1";
		$rows = kernel::database()->select($sql);
		$goods_type = array();
		foreach($rows as &$v) {
			$goods_type[$v['type_id']] = $v;
		}

		//获取商品分类的映射数组
		$sql = "select * from sdb_b2c_goods_cat where 1";
		$rows = kernel::database()->select($sql);
		$goods_cat = array();
		foreach($rows as &$v) {
			$goods_cat[$v['cat_id']] = $v;
		}

		$arr=array();$proCode='';
		foreach ($goods as & $value) {
			//获取扩展属性
			$type_id = $value['type_id'];
			if(!$arr_props[$type_id]) continue;
			//得到类型描述中对应的goods_p,和goods表中的p_?对应
			foreach($arr_props[$type_id] as &$vv) {
				$value['props'][$vv['name']] = $value["p_{$vv['goods_p']}"];
				//从goods_type_props中获得type_id相对应的属性,type=input|select,如果为select从goods_type_props_value中获得相应的描述
				if($vv['type']=='select') {
					$value['props'][$vv['name']] = $arr_props_value[$value["p_{$vv['goods_p']}"]]['name'];
				}
			}

			//获取货品信息
			$filter['goods_id']=$value['goods_id'];
			$products = $modelProduct->getList('*', $filter);
			foreach ($products as $key=>& $p) {
				$bn=$modelProduct->getBnJxc($p['bn']);
				//将member_id 全部取出  来判断是否有删除的数据  暂时不考虑
				// $proCode.= $bn['bn'].',';

				//最后更新时间小于最后修改时间  提高效率
//				if($params['last_modify']>=$p['last_modify']) continue;
				//取得颜色
				$color='';
				$spec=explode('、', $p['spec_info']);
				foreach ($spec as & $s) {
					$temps=explode('：', $s);
					if($temps[0]=='颜色'){
						$color=$temps[1];
						break;
					}
				}

				$value['products'][$bn['bn']]=array(
						'color'=>$color
					);
				$arr[$bn['bn']]=array(
						// 'name'=>$value['name'],
						'props'=>$value['props'],
						// 'color'=>$color,
						'danjia'=>$p['price'],
						'wuliaoKind'=>$goods_type[$value['type_id']]['name'],
						// 'zuzhi'=>$goods_cat[$value['cat_id']]['cat_name'],
						// 'brief'=>$value['brief'],
					);


			}
		}
		// return array('data'=>$arr,'bn'=>$proCode);
		return $arr;
	}


	/**
	 * @desc 商品类型
	 * @param type $params
	 * @param type $service
	 * @return type
	 */
	function get_goods_type($params, &$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('b2c')->model('goods_type')->getList('type_id,is_physical,setting,name,alias', $filter);
	}

	/**
	 * @desc 商品品牌
	 * @param type $params
	 * @param type $service
	 * @return type
	 */
	function get_brand($params, &$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('b2c')->model('brand')->getList('brand_id,brand_name,brand_url', $filter);
	}


	/**
	 * @desc 更新订单结算状态
	 * @author zhangweifeng@shopex.cn 15-7-20 下午2:47
	 */
	function update_order_settlement_status($params, &$service) {
		$update_result = kernel::single('b2c_order_status')->update_settlement($params['order_id'], $msg);
		if (!$update_result) {
			return $service->send_user_error('', $msg);
		}
		return $update_result;
	}


    /**
	 * @desc订单信息
	 * @author wang@shopex.cn2017/9/3
	 */
    function change_ship_orders($params, &$service) {
		$m = app::get('b2c')->model('orders');
		$mm = app::get('b2c')->model('order_log');
		$deliveryMdl = app::get('b2c')->model('delivery');
		$oCorp = app::get('b2c')->model('dlycorp');
		// $arr=$m->getList('order_id,ship_addr,status');
		//限制同步1000数据 wang 2017/12/27
		$con = "";
		//2018-8-13 by jeff,有些订单超出范围,需要通过以下条件来定位订单号进行同步,人工进行
		//$con = "order_id in('180724131849829','180724121822097','180718104749923')";
		$sql="select order_id,ship_addr,status,ship_name,ship_mobile from sdb_b2c_orders where 1 and {$con} order by createtime desc limit 1000";
		$arr=kernel::database()->select($sql);

		$cnt = $m->count($filter);

		return array('success'=>'true','msg'=>'成功同步 '.$cnt.' 条ec订单!','filter'=>$arr);
	}

	/**
	 * @desc 同步订单发货地址
	 * @author guomin
	 * @date 2018/9/4  10:23
	 * @param $params
	 * @param $service
	 * @return array
	 */
	public function order_delivery_path($params,&$service){
		$m = app::get('b2c')->model('orders');
		$order_id=$params['order_id'];
		$ret=$m->getRow('order_id,ship_addr,ship_name,ship_mobile', array('order_id'=>$order_id));
		return array('success'=>'true','msg'=>'获取成功!','data'=>$ret);
	}
    /**
     * @desc 订单打折审核信息
     * @author guomin
     * @date 2018/5/16  14:52
     * @param  array $params
     * @param object $service
     * @return array
     */
	public function get_order_discount($params,&$service){
        $order_id=$params['order_id'];
        $m = app::get('b2c')->model('order_apply_sale');
        $ret=$m->getList('*',array('order_id'=>$order_id,'shenhe_status'=>1));
        return array('success'=>'true','msg'=>'获取成功!','data'=>$ret);
    }

	/**
	 * @desc 通过花型六位号 查找对应货品id
	 * @author guomin
	 * @date 2018/6/16  19:47
	 * @param $params
	 * @param $service
	 * @return array
	 */
    public function get_product_id($params,&$service){
		$productId=$params['productId'];
		$m=app::get('b2c')->model('products');
		$ret=$m->getRow('product_id',array('bn'=>$productId.'-xh'));
		$product_id=$ret['product_id'];
	    $qrcode_image_id = kernel::single('weixin_qrcode')->get_jxc_qrcode_image_id($product_id);
	    $image=app::get('image')->model('image')->getRow('url',array('image_id'=>$qrcode_image_id));
		$ret['qrcode_url']=$image;
		return array('success'=>true,'msg'=>'获取成功','data'=>$ret);
    }
	/**
	 * @descorder_items订单号
	 * @author wang@shopex.cn2017/11/24
	 */
	function change_ship_order_items($params,&$service){

         $orders=app::get('b2c')->model('orders');
         $arrs=$orders->getList('order_id');
         // return $arr;
         //foreach($arrs as $ke=> $val){
         	$o = app::get('b2c')->model('order_items');
         	$tmp = $o->getList('order_id,name,price,madan_ids', array('madan_ids'));
         	// return $tmp;
         //}

		$cnt = $o->count($filter);

		return array('success'=>'true','msg'=>'成功同步 '.$cnt.' 条ec订单!','filter'=>$tmp);
	}


	/**
	 * @desc ：ERP打印发货单时调用，修改相关订单的发货状态字段,
	 * @author jeff 2015/07/22 10:10:37
	 * @param 参数类型
	 * @return 返回值类型
	*/
	function change_ship_status($params, &$service) {
		$m = app::get('b2c')->model('orders');
		$mm = app::get('b2c')->model('order_log');
		$deliveryMdl = app::get('b2c')->model('delivery');
		$oCorp = app::get('b2c')->model('dlycorp');
		foreach ($params['data'] as $key => & $v) {
			if(!$v['order_id'] || !$v['status']){
				continue;
			}
			//发货成功解冻库存 by lsc2017年3月28日13:21
	        $is_unfreeze = $this->unfreezeGoods($v['order_id']);
			$arr_data['ship_status'] = $v['status'];
			$arr_data['order_id'] = $v['order_id'];
			$r = $m->save($arr_data);
			$aCorp = $oCorp->getList('*',array('name'=>$v['corp_name']));

			$log_text['items'] = array(
				'txt_key'=>stripslashes('订单<a href="javascript:void(0)" onclick=\'show_delivery_item(this,"%s",%s)\' title="点击查看详细" style="color: rgb(0, 51, 102); font-weight: bolder; text-decoration: underline;"></a>已发货'),
				'data'=>array(
				  0=>$v['order_id'],
				  1=>htmlentities(json_encode($arr_items), ENT_QUOTES),
				),
			  );
			  // if ($aCorp) {
				$log_text['dlycorp'] = array(
				  'txt_key'=>'，物流公司：<a class="lnk" target="_blank" title="%s" href="%s">%s</a>（可点击进入物流公司网站跟踪配送）',
				  'data'=>array(
					0=>$v['corp_name'],
					1=>$aCorp['0']['request_url'],
					2=>$v['corp_name'],
				  ),
				);
			  // }
			  if ($v['logi_no']) {
				$log_text['logi_no'] = array(
				  'txt_key'=>"物流单号：%s",
				  'data'=>array(
					0=>$v['logi_no'],
				  ),
				);

				$log_addon['logi_no'] = $v['logi_no'];
				$log_addon = serialize($log_addon);
			  }
			$log_text = serialize($log_text);

			$arr_log['rel_id'] = $v['order_id'];
			$arr_log['op_name'] = '进销存发货';
			$arr_log['alttime'] = time();
			$arr_log['bill_type'] = 'order';
			$arr_log['behavior'] = 'delivery';
			$arr_log['result'] = 'success';
			$arr_log['log_text'] = $log_text;
			$arr_log['log_addon'] = $log_addon;

			$result=$mm->getList('*',array('rel_id'=>$v['order_id'],'behavior'=>'delivery'));
			if(!$result){
			  $r = $mm->save($arr_log);
			}else{
			  $arr_log['log_id'] = $result[0]['log_id'];
			  $r = $mm->save($arr_log);
			}
			$arr['delivery_id'] = $v['order_id'];
			$arr['order_id'] = $v['order_id'];
			$arr['logi_id'] = $aCorp['0']['corp_id'];
			$arr['logi_name'] = $aCorp['0']['name'];
			$arr['logi_no'] = $v['logi_no'];
			$r = $deliveryMdl->save($arr);

			//2017-1-3 by jeff,修改订单表中的发货时间字段
			$rowOrder = array(
			  'order_id'=>$v['order_id'],
			  'real_ship_time'=>date('Y-m-d H:i:s')
			);
			$m->save($rowOrder);
			//发货成功推送微信消息;2017年7月13日16:52:12 lsc
        	$this->pushWeixin($m,$v);
		}

		if(!$r) return array('success'=>'false','msg'=>'修改失败');
		//取得成功条数
		$cnt = $m->count($filter);

		return array('success'=>'true','msg'=>'成功同步 '.$cnt.' 条ec订单!','filter'=>$filter);
	}

	private function unfreezeGoods($order_id)
    {
        $is_unfreeze = true;
        $subsdf = array('order_objects'=>array('*',array('order_items'=>array('*',array(':products'=>'*')))));
        $sdf_order = app::get('b2c')->model('orders')->dump($order_id, 'order_id,status,pay_status,ship_status', $subsdf);

        // 所有的goods type 处理的服务的初始化.
        $arr_service_goods_type_obj = array();
        $arr_service_goods_type = kernel::servicelist('order_goodstype_operation');
        foreach ($arr_service_goods_type as $obj_service_goods_type)
        {
            $goods_types = $obj_service_goods_type->get_goods_type();
            $arr_service_goods_type_obj[$goods_types] = $obj_service_goods_type;
        }

        $objGoods = app::get('b2c')->model('goods');
        foreach($sdf_order['order_objects'] as $k => $v)
        {
            if ($v['obj_type'] != 'goods' && $v['obj_type'] != 'gift')
            {
                foreach( kernel::servicelist('b2c.order_store_extends') as $object ) {
                    if( $object->get_goods_type()!=$v['obj_type'] ) continue;
                    $obj_extends_store = $object;
                    if ($obj_extends_store)
                    {
                        $obj_extends_store->store_change($v, 'cancel');
                    }
                }
                continue;
            }

            foreach ($v['order_items'] as $arrItem)
            {
                if ($arrItem['item_type'] == 'product')
                    $arrItem['item_type'] = 'goods';
                $arr_params = array(
                    'goods_id' => $arrItem['products']['goods_id'],
                    'product_id' => $arrItem['products']['product_id'],
                    'quantity' => $arrItem['quantity'],
                );
                $str_service_goods_type_obj = $arr_service_goods_type_obj[$arrItem['item_type']];
                $is_unfreeze = $str_service_goods_type_obj->unfreezeGoods($arr_params);
            }
        }

        return $is_unfreeze;
    }
	/**
	 * @desc ：ERP撤销发货单时调用，重置相关订单的发货状态字段,
	 * @author jeff 2015/07/22 10:10:37
	 * @param 参数类型
	 * @return 返回值类型
	*/
	function reset_ship_status($params, &$service) {
		$arr_order_id = $params['arr_order_id'];
		/*
		0 => app::get('b2c')->_('未发货'),
		1 => app::get('b2c')->_('已发货'),
		2 => app::get('b2c')->_('部分发货'),
		3 => app::get('b2c')->_('部分退货'),
		4 => app::get('b2c')->_('已退货'),
		*/
		$ship_status = 0;
		$m = app::get('b2c')->model('orders');
		$filter = array('order_id'=>$arr_order_id);
		$r = $m->update(array('ship_status'=>$ship_status),$filter);
		if(!$r) return array('success'=>'false','msg'=>'修改失败');
		return array('success'=>'true','msg'=>'取消发货状态成功!');
	}

	/**
	 * @desc ：重置订单状态为正常状态(erp拒绝退款时触发)
	 * @author jeff 2015/08/02 11:29:39
	 * @param 参数类型
	 * @return 返回值类型
	*/
	function reset_order_status($params, &$service) {
		$update_result = kernel::single('b2c_order_status')->reset_order($params['order_bn'], $msg);
		if (!$update_result) {
			return $service->send_user_error('', $msg);
		}
		return $update_result;
	}

	/**
	 * @desc 同步ERP中的相同账户的密码到EC
	 * @time 2015-08-18 20:51
	 */
	function sysn_password_erp2ec($params,&$service) {
		return $param;

		return array("msg"=>"同步ERP密码到EC相同用户成功！");
	}

	/**
	 * @desc 同步ERP的数据到EC
	 * @time 2015-08-24 15:55
	 */
	function sync_erp2ec_by_notice($params,&$service){
		$notice_type=$params['notice_type'];
		$haystack=array('BRANCH','BRANCH_PRODUCT');
		if(in_array($notice_type, $haystack)){
			switch ($notice_type) {
				case 'BRANCH':
					$sync_obj=  kernel::single("b2c_tasks_branch_default");
					$sync_obj->exec();
					break;
				case 'BRANCH_PRODUCT':
					$sync_obj=  kernel::single("b2c_tasks_branch_product");
					$sync_obj->exec();
					break;
				default:
					break;
			}
		}
	}

	/**
	 * @desc 返回所有的渠道数据
	 * @time 2015-08-24 17:36
	 * @author Mark
	 */
	function get_channel($params,&$service) {
		$filter = array();
		if (!empty($params['last_modify'])) {
			$filter['last_modify|bthan'] = $params['last_modify'];
		}
		return app::get('b2c')->model('channel')->getList('*', $filter);
	}


	/**
	 * 获取配送方式和物流公司
	 * Time：2015/09/18 14:13:25
	 * @author li
	 * @param delivery=true需要获取配送方式
	 * @param logi_id=true需要获取物流方式
	 * @return array
	*/
	function get_delivery($params=array(), &$service=null){
		$delivery = $params['delivery'];
		$logi_id = $params['logi_id'];

		$_arr = array();
		$delivery == true && $_arr['dlytype'] = $this->get_dlytype();
		$logi_id == true && $_arr['dlycorp'] = $this->get_dlycorp();

		return $_arr;
	}

	/**
	 * 获取物流公司
	 * Time：2015/09/18 14:16:22
	 * @author li
	*/
	function get_dlycorp(){
		$dlycorp_list = app::get('b2c')->model('dlycorp')->getList('corp_id,name,corp_code');
		return $dlycorp_list;
	}

	/**
	 * 获取配送方式
	 * Time：2015/09/18 14:16:22
	 * @author li
	*/
	function get_dlytype(){
		$filter['dt_status|tequal'] = 1;

		$dlytype_list = app::get('b2c')->model('dlytype')->getList('dt_id,dt_name',$filter);
		return $dlytype_list;
	}

	/**
	 * 同步进发货记录
	 * 可以支持多条记录一起同步
	 * Time：2015/09/21 18:00:09
	 * @author li
	 * @param send_data array 多条发货
	*/
	function do_delivery($params = array(), &$service=null){
		$data = $params['send_data'];
		if(!isset($data) || !$data){
		  return array('error'=>'数据为空，不能同步发货');
		  exit;
		}
		$b2c_order_items = app::get('b2c')->model('order_items');
		$result = array();
		// dump($data);exit;
		if($data)foreach ($data as & $v) {
		  foreach ($v['send'] as & $s) {
			//查找订单明细id
			$sql = "SELECT item_id from sdb_b2c_order_items where bn = '{$s['bn']}'";
			$arr=$b2c_order_items->db->select($sql);
			$arr = $arr[0];
			$_send[$arr['item_id']] = $s['cnt'];
		  }

		  $v['send'] = $_send;
		  //一条一条同步
		  $_result=array();
		  $_result = $this->do_delivery_one($v);
		  $_result['bn'] = $s['bn'];
		  $result[] = $_result;
		}
		// dump($result);exit;
		return $result;

	}

	/**
	 * 处理发货信息
	 * Time：2015/09/21 18:13:34
	 * @author li
	*/
	function do_delivery_one($sdf){
		//订单处理的controller
		$db = kernel::database();
		$transaction_status = $db->beginTransaction();
		// $db->commit($transaction_status);
		// $db->rollback();

		$_controller = app::get('b2c')->controller('admin_order');
		$_controller = null;
		// $_controller = kernel::single('b2c_ctl_admin_order');

		//开始事务
		// $_controller->begin();
		$app = app::get('b2c');
		$objB2c_delivery = b2c_order_delivery::getInstance($app, $app->model('delivery'));
		// dump($objB2c_delivery);exit;
		// if ($objB2c_delivery->generate($sdf, $_controller, $_message)){
		if ($objB2c_delivery->generate($sdf, $_controller, $_message)){
		  if($order_object = kernel::service('b2c_order_rpc_async')){
			  $order_object->modifyActive($sdf['order_id']);
		  }
		  // $_controller->endonly(true);
		  $db->commit($transaction_status);
		  return array('success'=>true,'msg'=>$_message);
		}
		// $_controller->endonly(false);
		$db->rollback();
		return array('success'=>false,'msg'=>$_message);

	}
	/**
	 * ps ：进销存退换货完成信息，同步
	 * Time :2015/10/09 12:40:49
	 * @author 张艳
	 * @param 参数类型
	 * @return 返回值类型
	*/
	function do_finish_redelivery($params = array(), &$service=null){
		$data = $params;
		if(!isset($data) || !$data){
		  return array('error'=>'数据为空，不能同步完成');
		  exit;
		}
		$obj_return_policy = kernel::single('aftersales_data_return_policy');
		$return_id = $data['return_id'];
		$status = $data['status'];
		$sdf = array(
			'return_id' => $return_id,
			'status' => $status,//从进销存传来两种状态：4完成，5拒绝
		);
		$result = $obj_return_policy->change_status($sdf);
		/*
		主订单的ship_status：3部分退货，4已退货，5取消发货。
		当进销存状态为完成时：判断退换货表中此订单已退换成功的数量：若已退总数量<订单总数量，则主订单的ship_status为部分退货
		若已退总数量=订单总数量，则主订单的ship_status为已退货
		*/
		if ($status==4) {
        	$returnProduct = app::get('aftersales')->model('return_product');
        	$datas = $returnProduct->getList('order_id,product_data',array('order_id'=>$data['order_id'],'type'=>1,'status'=>4));
        	$yiTuinumSum = 0;//已退总数量
        	foreach ($datas as  &$value) {
        		$value['product_data'] = unserialize($value['product_data']);
        		foreach ($value['product_data'] as $val) {
        			$yiTuinumSum += $val['num'];
        		}
        	}
        	$orders = app::get('b2c')->model('orders');
        	$orderNumSum = $orders->getRow('itemnum',array('order_id'=>$data['order_id']));
        	$orderNumSum = $orderNumSum['itemnum'];
        	if ($yiTuinumSum<$orderNumSum) {
        		$ship_status = 3;
        	}else{
        		$ship_status = 4;
        	}
        	$orders->update(array('ship_status'=>$ship_status),array('order_id'=>$data['order_id']));
		}
		return array('success'=>'true','msg'=>'退换货完成！');
	}
	/**
	 * ps ：进销存入库完成-发送通知
	 * Time :2017年4月7日13:36
	 * @author 蔺苏川
	 * @param 参数类型
	 * @return 返回值类型
	*/
	// function supplement_notify($params = array(), &$service=null){
	// 	if ($params['setover']) {
	// 		$mdlProduct = app::get('b2c')->model('products');
	// 		if (is_array($params['productId'])) {
	// 			foreach ($params['productId'] as $key => $value) {
	// 				$bn = $value.'-yp';
	// 				$product_id = $mdlProduct->getRow('product_id',array('bn'=>$bn));
	// 				if ($product_id) {
	// 					$product_id = $product_id['product_id'];
	// 					kernel::single('b2c_goods_supplement')->notify($product_id);
	// 				}
	// 			}
	// 		}else{
	// 			$bn = $params['productId'].'-yp';
	// 			$product_id = $mdlProduct->getRow('product_id',array('bn'=>$bn));
	// 			if ($product_id) {
	// 				$product_id = $product_id['product_id'];
	// 				kernel::single('b2c_goods_supplement')->notify($product_id);
	// 			}
	// 		}
	// 	}
	// }

	function supplement_notify($params = array(), &$service=null){
		$mdlProduct = app::get('b2c')->model('products');
		$productId = $params['productId'];
		$productId = explode(',', $productId);
		$kernelObj = kernel::single('b2c_goods_supplement');
		foreach ($productId as $key => $value) {
			if ($params['type'] == 'Xianhuo') {
				$bn = $value.'-xh';
			} else {
				$bn = $value.'-yp';
			}
			//products表中的product_id
			$product_id = $mdlProduct->getRow('product_id',array('bn'=>$bn));
			$product_id = $product_id['product_id'];
			$kernelObj->notify($product_id);
		}
	}
	function change_refund_status($params, &$service){
		$data = array(
			'status'=>$params['status'],
			'apply_id'=>$params['apply_id'],
			'refund_type'=>$params['refund_type'],
			'memo'=>$params['memo'],
		);
		kernel::single('aftersales_data_refund')->changeRefund($data);
	}
	//开票api
	function change_apply_billing($params,&$service){
		$aData=array(
			'status'=>$params['status'],
			'billing_id'=>$params['billing_id'],
			'billing_money'=>$params['billing_money'],
			'memo'=>$params['memo'],
		);

		kernel::single('aftersales_data_billing')->changeBill($aData);
	}
	//推送微信消息
    public function pushWeixin($mdl,$data){
    	$orderInfo = $mdl->getRow('member_id,ship_addr',array('order_id'=>$data['order_id']));
        $member_id = $orderInfo['member_id'];
        $open_id = app::get('pam')->model('bind_tag')->getRow('open_id',array('member_id'=>$member_id,'tag_type'=>'weixin'));
        //添加物流名称，物流编号 by wang 2017/12/11
        $deliverId=app::get('b2c')->model('delivery');
        $rowstr=$deliverId->getList('*',array('order_id'=>$data['order_id']));

        if ($open_id['open_id']) {
            $temp_id = app::get('b2c')->getConf('weixin.push.deliver.tempid');
            $params = array(
            'first' => array(
                'value' => "您的订单已发货",
                'color' => '#003366',
            ),
            'keyword1' => array(//订单编号
                'value' => $data['order_id'],
                'color' => '#003366',
            ),
            'keyword2' => array(//收货地址
                'value' => $orderInfo['ship_addr'],
                'color' => '#003366',
            ),
            'keyword3' => array(//物流名称
                'value' => $rowstr[0]['logi_name'],
                'color' => '#333',
            ),
            'keyword4' => array(//物流编号
                'value' => $rowstr[0]['logi_no'],
                'color' => '#003366',
            ),
            'keyword5' => array(//发货时间
                'value' => date('Y-m-d H:i',time()),
                'color' => '#003366',
            ),
            'remark' => array(
                'value' => "客服热线：400-1133-885\n客服QQ：3001119499\n感谢您的光临！",
                'color' => '#333',
            )
        );
            $res = kernel::single('weixin_base')->sendTempleteMsg($temp_id,$params,$open_id['open_id'],$ret_url);
        }
    }
    /*
	*帕西菲克 相关接口
	*
    */
    //1.获取商城会员收货地址列表接口
    public function pxfk_getmember_addrs($params,&$service){
    	/*获取收货地址 start*/
    	$username = $params['username'];
        $data = kernel::single('b2c_member_addrs')->get_addr_byusername($username);
        $objRegions =  app::get('ectools')->model('regions');
        foreach ($data as $key => &$value) {
        	$regionPath = $objRegions->getRow('region_path',array('region_id'=>$value['region_id']));
        	$value['region_path'] = trim($regionPath['region_path'],',');
        }
        if (!$data) {
			return $service->send_user_error('', '请到商城会员中心设置收货地址!');
        }
        return $data;
    }
    //2.订单保存接口
    public function pxfk_create_order($params,&$service){
    	dump2file2($params,'create_order.txt');
    	//获取收货地址信息
    	$addrs = app::get('b2c')->model('member_addrs')->getRow('*',array('addr_id'=>$params['addrId']));
    	$order = app::get('b2c')->model('orders');
    	$mdlProducts = app::get('b2c')->model('products');
    	foreach ($params['orderitems'] as $key => $value) {
    		$productsInfo = $mdlProducts->getRow('goods_id',array('product_id'=>$value['productid']));
    		$goods_id = $productsInfo['goods_id'];
    		$order_objects[$key] = array(
                'order_id'=>$params['orderId'],
                'goods_id'=>$goods_id,
                'obj_alias'=>'成衣定制',
                'obj_type'=>'goods',
                'quantity'=>$value['nums'],
                'order_items'=>array(
                    array(
                        'products'=>array(
                            'product_id'=>$value['productid']
                        ),
                        'goods_id' => $goods_id,
                        'order_id' => $params['orderId'],
                        'item_type' => 'product',
                        'name' => $value['bn'],
                        'type_id' => '2',
                        'cost' => '0.000',
                        'price'=>$value['price'],
                        'g_price'=>$value['price'],
                        'amount'=>$value['price'],
                        'quantity' => $value['nums'],
                        'juanshu' => 1,
                        'madan_ids' => ' ',
                        'cntM' => ' ',
                        'peihuoCodes' => ' ',
                        'sendnum' => 0,
                        'bn' => $value['bn'].'-pxfk',
                        'haveStock'=>$value['haveStock'],
                        'orderIdSon'=>$value['orderIdSon'],
                        'memo'=>$value['memo'],
                        'pxfk_unitPrice'=>$value['pxfk_unitPrice'],//面料价格
                        'pxfk_unitM'=>$value['pxfk_unitM'],//面料单耗
                        'jiagong_price'=>$value['jiagong_price'],//加工费
                        'gongyi_price'=>$value['gongyi_price'],//工艺价格
                    ),
                ),
            );
            $itemnums += $value['nums'];
            $orderPrice += $value['price'];
    	}
        $orderDatas = array(
            'order_id'=>$params['orderId'],
            'order_type'=>'pxfk',
            'member_id'=>$params['userId'],
            'createtime'=>time(),
            'itemnum'=>$itemnums,
            'shipping'=>array(
                'shipping_id'=>0,
                'is_protect'=>false,
                'cost_shipping'=>$params['freight'],
                'cost_protect'=>0,
            ),
            'payinfo'=>array(
                'pay_app_id'=>$params['pay_app_id'],
                'cost_payment'=>'0',
            ),
            'cost_item'=>round($orderPrice,3),//订单商品总价格
            'total_amount'=>round($orderPrice+$params['freight'],3),//商品默认货币总值
            'cur_amount'=>round($orderPrice+$params['freight'],3),//订单总额
            'score_g'=>round($orderPrice+$params['freight'],3),//订单总额获得的积分
            'currency'=>'CNY',
            'consignee'=>array(
                'name'=>$addrs['name'],
                'addr'=>$addrs['addr'],
                'zip'=>$addrs['zip'],
                'telephone'=>$addrs['tel'],
                'mobile'=>$addrs['mobile'],
                'area'=>$addrs['area'],
                'r_time'=>'任意时间,任意时间段'

            ),
            'haveStock'=>$params['haveStock'],
            'order_objects'=>$order_objects,
            'memo'=>$params['memo'],
        );
    	if ($result = $order->save($orderDatas,null,true)) {
    		return $result;
    	}else{
			return $service->send_user_error('', '订单创建失败!');
    	}

    }

    //3.定制平台发货请求接口
    public function pxfk_change_ship_status($params,&$service){
    	dump2file2($params,'ship_status.txt');
    	//根据发货的子订单号判断是部分发货还是全部发货
    	$objOrderItems = app::get('b2c')->model('order_items');
    	$orderItemsInfo = $objOrderItems->getList('*',array('order_id'=>$params['orderId']));
    	//本次发货的子订单
    	$nowOrderSon = utils::_array_column($params['orderitems'],'orderIdSon');
    	//已经发货的子订单
    	$alreadyDelivery = array();
    	foreach ($orderItemsInfo as $key => $value) {
			if ($value['sendnum']>0) {
				$orderItemsDelivery[]=$value;
				$alreadyDelivery[] = $value['orderIdSon'];
			}
			//所有子订单
			$allOrderSon[] = $value['orderIdSon'];
    	}
    	//本次发货的子订单+已经发货的子订单：
    	$mergerOrderSon = array_merge($nowOrderSon,$alreadyDelivery);
    	$mergerOrderSon = array_unique($mergerOrderSon);
    	//比较差集=是否有未发货的
    	$noDeliverOrderson = array_diff($allOrderSon, $mergerOrderSon);
    	if ($noDeliverOrderson) {
    		$ship_status = 0;//有未发货的，主订单信息=未发货
    	}else{
    		$ship_status = 1;
    	}
		$mdlOrders = app::get('b2c')->model('orders');
		$mdlOrderLog = app::get('b2c')->model('order_log');
		$deliveryMdl = app::get('b2c')->model('delivery');
		$db = kernel::database();
		$arr_data['ship_status'] = $ship_status;
		$arr_data['order_id'] = $params['orderId'];
		$r = $mdlOrders->save($arr_data);
		$time = time();
		foreach ($params['orderitems'] as $key => $value) {
			$sql0 = "INSERT INTO sdb_b2c_delivery (order_id,delivery_bn,logi_name,logi_no,corp_code,t_begin) VALUES({$params['orderId']},{$value['orderIdSon']},'{$value['corp_name']}','{$value['logi_no']}','{$value['corp_code']}',{$time})";
            $db->exec($sql0);
            $insert_id = $db->lastinsertid();
            $sql1 = "INSERT INTO sdb_b2c_order_delivery (order_id,dlytype,dly_id) VALUES({$params['orderId']},'delivery','{$insert_id}')";
            $db->exec($sql1);
			//更新子订单发货数量
			$sql = "UPDATE sdb_b2c_order_items a set a.sendnum=a.nums WHERE orderIdSon='{$value['orderIdSon']}'";
			$db->exec($sql);
			//日志数据：
			$log_text['items'][] = $value;
		}
		$log_text = serialize($log_text);
		$arr_log['rel_id'] = $params['orderId'];
		$arr_log['op_name'] = '帕西菲克发货';
		$arr_log['alttime'] = time();
		$arr_log['bill_type'] = 'order';
		$arr_log['behavior'] = 'delivery';
		$arr_log['result'] = 'success';
		$arr_log['log_text'] = $log_text;
		$mdlOrderLog->save($arr_log);
		//通知进销存已发货处理相关事件：订单更新发货、财务过账收款
		//发货成功推送微信消息;2017年7月13日16:52:12 lsc
    	$this->pushWeixin($mdlOrders,$params);
		return ture;
    }
    //4.定制平台审核订单取消接口
    public function pxfk_cancel_order_shenhe($params, &$service){
    	$order = app::get('b2c')->model('orders');
    	$orderInfo = $order->getRow('member_id,payment,total_amount,createtime',array('order_id'=>$params['orderId']));
    	$db = $order->db;
        // $is_update = $order->update(array('cancel_status'=>$params['cancel_status'],'status'=>'dead'),array('order_id'=>$params['orderId']));
        $updateSql = "UPDATE sdb_b2c_orders SET cancel_status = '{$params['cancel_status']}',status='dead' where order_id = '{$params['orderId']}' ";
        $source = $db->exec($updateSql);
        $is_update = $db->affect_row();
        if ($is_update) {
            $objorder_log = app::get('b2c')->model('order_log');
            $log_text[] = array(
				'txt_key'=>'订单取消'.'('.$params['cancel_status'].')',
				'data'=>array(
				),
			);
			$log_text = serialize($log_text);
        	$sdf_order_log = array(
                'rel_id' => $params['orderId'],
                'op_id' => 0,
                'op_name' => '帕西菲克审核取消订单',
                'alttime' => time(),
                'bill_type' => 'order',
                'behavior' => 'cancel',
                'result' => 'SUCCESS',
                'log_text' => $log_text,
            );
            $log_id = $objorder_log->save($sdf_order_log);
            //已支付的订单审核取消-定制平台同意取消，jxc需要做相关处理：订单状态、财务退款...todo
        	$post = array(
	            'method'=>'pxfk.cancel.order.shenhe',
	            'params'=>array(
	                'orderId'=>$params['orderId'],
	                'cancel_status'=>$params['cancel_status'],
					'member_id'=>$orderInfo['member_id'],
	                'money'=>$orderInfo['total_amount'],
					'payment'=>$orderInfo['payment'],
					'createtime'=>$orderInfo['createtime'],
            	)
    		);
	        $erp_caller_obj = kernel::service('apioubao.rpc_erp_request');
	        $result = $erp_caller_obj->call_api_oubao($post);
        }
        return true;
    }
    //5.定制平台获取全国地址接口
    public function pxfk_get_arealist($params, &$service){
    	$obj_region = app::get('ectools')->model('regions');
        $areas = $obj_region->getList('region_id,local_name,p_region_id',array(),0,-1,'region_id asc');
        /*$a=0;
        foreach ($areas as $key => $value) {
        	if ($value['region_grade']==1) {
        		$province[$a]['region_id']= $value['region_id'];
        		$province[$a]['p_region_id']= $value['p_region_id'];
        		$province[$a]['local_name']= $value['local_name'];
        		$a++;
        	}
        	if ($value['region_grade']==2) {
        		foreach ($province as $ke => &$val) {
        			if ($value['p_region_id']==$val['region_id']) {
        				$val['children2'][] = $value;
        			}
        		}
        	}
        	if ($value['region_grade']==3) {
        		foreach ($province as $ke => &$val) {
        			foreach ($val['children2'] as $k => &$v) {
        				if ($value['p_region_id']==$v['region_id']) {
        					$v['children3'][] = $value;
        				}
        			}
        		}
        	}
        }*/
        $arealist = $this->getChild($areas);
        return $arealist;
    }

	/**递归无限分类
	 * @param $arr 数组
	 * @param $id   id
	 * @param $level  层级
	 * @return array
	 */
	function demo($arr,$id,$level)
	{
	    $list =array();
	    foreach ($arr as $k=>$v){
	        if ($v['p_region_id'] == $id){
	            $v['level']=$level;
	            $v['children'] = $this->demo($arr,$v['region_id'],$level+1);
	            $list[] = $v;
	        }
	    }
	    return $list;
	}

	//引用无限分类
	function getChild($data){
        $tree = array();
        $newData = array();
        //循环重新排列
        foreach ($data as $datum) {
            $newData[$datum['region_id']] = $datum;
        }
        foreach ($newData as $key => $datum) {
            if ($datum['p_region_id'] > 0) {
                //不是根节点的将自己的地址放到父级的child节点
                $newData[$datum['p_region_id']]['child'][] = &$newData[$key];
            } else {
                //根节点直接把地址放到新数组中
                $tree[] = &$newData[$datum['region_id']];
            }
        }
        return $tree;
    }
    //6.定制平台获取面料单价接口
	function pxfk_get_price($params, &$service){
		$memberLv = app::get('b2c')->model('members')->getList('member_lv_id',array('member_id'=>$params['userid']));
        $customMPrice = app::get('b2c')->model('goods_lv_price')->getRow('*',array('product_id'=>$productId,'level_id'=>$memberLv[0]['member_lv_id']));
        if($customMPrice){
            $price = $customMPrice['price'];
        }else{
        	$pruductPrice = app::get('b2c')->model('products')->getRow('price',array('product_id'=>$params['productid']));
            $memberDiscout = app::get('b2c')->model('member_lv')->getList('member_lv_id,name,dis_count',array('member_lv_id'=>$memberLv[0]['member_lv_id']));
            $price =$pruductPrice['price'] * $memberDiscout[0]['dis_count'];
        }
        $ret = array();
        //获取未备货面料的运费单价：元/米
        $nostockFreight = app::get('b2c')->getConf('nostock.price');
        $ret['nostockFreight'] = $nostockFreight;
        $ret['price'] = $price;
        return $ret;
    }
    //7.定制平台修改、新增会员地址接口
    function pxfk_savemember_addrs($params,&$service){
    	$data = array(
    		'addr_id'=>$params['addr_id'],
    		'area'=>'mainland:'.$params['area'].':'.$params['region_id'],
    		'addr'=>$params['addr'],
    		'zip'=>$params['zip'],
    		'name'=>$params['name'],
    		'mobile'=>$params['mobile'],
    		'def_addr'=>$params['def_addr']?$params['def_addr']:0,
    	);
    	$save_data = kernel::single('b2c_member_addrs')->purchase_save_addr($data,$params['userid'],$msg);
        if(!$save_data){
			return $service->send_user_error($msg);
        }else{
        	return true;
        }
    }
    function jxc_pxfkSaveRefund($params,&$service){
    	$db = kernel::database();
        $db->beginTransaction();
    	//1.更新订单状态已退款status=dead，pay_status=5,全额退款
    	$sqlOrder = "UPDATE sdb_b2c_orders set status='dead', pay_status='5' where order_id='{$params['orderCode']}'";
    	$db->exec($sqlOrder);
        $ret1 = $db->affect_row();
    	if ($params['refundType'] == 'deposit') {
    		$userObject = kernel::single('b2c_user_object');
	        $mem_shenhe = app::get('b2c')->model('member_shenhe');//会员预存款审核记录表
	        $data['modify_advance'] = $params['money'];
	        $data['modify_advance_type'] = 0;
	        $data['modify_memo'] = '预存款退款,'.'帕西菲克订单号：'.$params['orderCode'];
	        $data['member_id']=$params['member_id'];
	        $data['mtime']=time();
	        $pam_member_info = $userObject->get_members_data(array('account'=>'login_account'),$params['member_id']);
	        $data['login_account'] = $pam_member_info['account']['login_account'];
        	$mem_shenhe->save($data);
        	$ret2 = $db->affect_row();
    	}else{
    		$ret2 = true;
    	}
        if ($ret1 && $ret2) {
        	$db->commit();
        	return true;
        }else{
        	$db->rollback();
			return $service->send_user_error('');
        }
    }
    function ec_test($params, &$service){
    	// $model = app::get('b2c')->model('orders');
    	// // $ret = $model->delete(array('order_id'=>'190620104023928'));
    	// $ret = $model->dump('1907010859230174');
    	$params = array (
  'orderCode' => '190718155706754',
  'Order' =>
  array (
    'orderCode' => '190718155706754',
    'money' => '7369.600',
    'youhui' => '0.000',
    'discount' => '0.000',
    'zhekoudiscount' => '0.000',
    'weight' => '65464.000',
    'money_order' => '7369.600',
    'pmt_goods' => '0.000',
    'pmt_order' => '0.000',
    'pay_status' => 1,
    'ship_status' => '0',
    'is_delivery' => 'Y',
    'orderTime' => '2019-07-18 15:57:46',
    'payment' => 'deposit',
    'clientId' => '879',
    'currency' => 'CNY',
    'shipping' => '上门自提',
    'ship_name' => '王先生',
    'ship_addr' => '甘肃金昌市金川区创研港13-A-502室',
    'ship_zip' => '2455254',
    'ship_tel' => '0519-80338365',
    'ship_email' => NULL,
    'ship_mobile' => '13306145213',
    'ship_area' => 'mainland:甘肃/金昌市/金川区:357',
    'is_tax' => 'false',
    'tax_type' => 'false',
    'tax_content' => NULL,
    'cost_tax' => '0.000',
    'tax_company' => NULL,
    'memo' => '',
    'biaoqian_memo' => NULL,
    'cur_rate' => '1.0000',
    'status' => 'active',
    'cost_freight' => '0.00',
    'order_type' => 'oubao',
    'addon' => false,
  ),
  'Pro' =>
  array (
    0 =>
    array (
      'productId' => '122748',
      'bn' => '122748-xh',
      'price' => '18.800',
      'danjia' => '18.800',
      'danjia_p' => '18.800',
      'cnt' => '392',
      'unit' => '',
      'kind' => '现货',
      'spec_info' => 'a:1:{s:12:"product_attr";a:1:{i:5;a:2:{s:5:"label";s:6:"类型";s:5:"value";s:6:"现货";}}}',
      'madan' => '177459,177460,177463,177464',
      'order_id' => '190718155706754',
      'peihuoCodes' => ' ',
      'item_type' => 'product',
      'money' => '7369.600',
    ),
  ),
);
    	$post = array(
            'method'=>'order.create',
            'params'=>$params
        );
        $erp_caller_obj = kernel::service('apioubao.rpc_erp_request');
        $result = $erp_caller_obj->call_api_oubao($post);
        $r = json_decode($result,true);
        $flag = $r['rsp']===false;
    	return $r;
    }

}
